<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/admin/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
  <link rel="stylesheet" href="/static/admin/lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">
  <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
  <div class="layuimini-main">
    <form class="layui-form">


          <div class="layui-form-item">
            <label class="layui-form-label">板块名称</label>
            <div class="layui-input-inline">
              <input type="text" name="plate_name" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">所属板块</label>
            <div class="layui-input-inline">
              <select name="pid" lay-verify="required" lay-search="">
                <option value="0">顶级板块</option>
                {if !empty($plates)}
                  {volist name="$plates" id="ps"}
                  <option value="{$ps.plate_id}">{$ps.plate_name}</option>
                  {/volist}
                {/if}
              </select>
            </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">所属类型</label>
          <div class="layui-input-inline">
            <select name="plate_type" lay-verify="required" lay-search="">
              <option value="1">文章</option>
              <option value="2">试题</option>
            </select>
          </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">板块排序</label>
            <div class="layui-input-inline">
              <input type="number" name="plate_sort"  value="0" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">板块图标</label>
            <div class="layui-upload-drag" id="upload">
              <i class="layui-icon"></i>
              <p>点击上传，或将文件拖拽到此处</p>
              <div class="layui-hide" id="uploadDemoView">
                <hr>
                <img src="" alt="上传成功后渲染" style="max-width: 196px">
                <input type="hidden" name="plate_head" value="">
              </div>
            </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" type="button" lay-submit="" lay-filter="zz_add">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
          </div>
        </div>
    </form>
  </div>
</div>
<script src="/static/admin/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
  layui.use(['form','upload'], function () {
    var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery
            ,upload = layui.upload;

    // 图片上传
    upload.render({
      elem: '#upload'
      ,url: '/back/upload/uploads' //改成您自己的上传接口
      ,done: function(res){
        layer.msg('上传成功');
        layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.path);
        layui.$('#uploadDemoView').find('input').attr('value', res.path);
        console.log(res)
      }
    });

    //监听提交
    form.on('submit(zz_add)', function (data) {
      data = data.field;
      $.ajax({
        url : '/back/plate/add',
        data :data,
        type:'POST',
        success:function(res){
          if(res.code == 1){
            layer.msg(res.msg,{icon:1,time:2000},function(){
              var index = parent.layer.getFrameIndex(window.name);
              parent.location.reload();
              parent.layer.close(index);
            });
          }else{
            layer.msg(res.msg,{icon:2});
          }

        }
      });
      return false;
    });



  });
</script>

</body>
</html>